package com.hqj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqj.controller.vo.HomeAllVo;
import com.hqj.dao.ResourceMapper;
import com.hqj.entity.ResourceEntity;
import com.hqj.service.ResourceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;

/**
 * @author 黄啟军
 * @version 1.0
 * @date 2020/7/23 0023
 */
@Service
public class ResourceServiceImpl implements ResourceService {
    @Resource
    private ResourceMapper resourceMapper;
    @Override
    public List<ResourceEntity> findAll() {
        QueryWrapper<ResourceEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",0);
        List<ResourceEntity> entityList = resourceMapper.selectList(wrapper);
        for (ResourceEntity resourceEntity : entityList){
            QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("parent_id",resourceEntity.getId());
           resourceEntity.setResourceList(resourceMapper.selectList(queryWrapper));
            queryWrapper = null;
        }
        return entityList;
    }

    @Override
    public HashSet<HomeAllVo> resourceHome() {
        QueryWrapper<ResourceEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",0);
        List<ResourceEntity> resourceEntities = resourceMapper.selectList(wrapper);
        HashSet<HomeAllVo> homeAllVos = new HashSet<>();
        for(ResourceEntity resourceEntity:resourceEntities){
            HomeAllVo allVo = new HomeAllVo();
            allVo.setClassifyCode(resourceEntity.getId());
            allVo.setClassifyName(resourceEntity.getName());
            homeAllVos.add(allVo);
        }
        return homeAllVos;
    }
}
